package com.hanrui.android.fragment.message.audit.officegood;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.OfficeGoodDetailBean;
import com.hanrui.android.net.contract.message.audit.officegood.OfficeGoodDetailContract;
import com.hanrui.android.net.presenter.message.audit.officegood.OfficeGoodDetailPresenter;

import butterknife.BindView;

/**
 * 办公用品审批基本信息
 *
 */

public class OfficeGoodDetailFragment extends BaseFragment<OfficeGoodDetailPresenter> implements OfficeGoodDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.leaders)
    TextView leaders;
    @BindView(R.id.duty_people)
    TextView dutyPeople;
    @BindView(R.id.ll_addview)
    LinearLayout llAddview;

    String taskId,procInsId,bizId;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_officegood;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.officeGoodBizDetail(getActivity(),taskId,procInsId,bizId);

    }



    public static OfficeGoodDetailFragment newInstance(String taskId, String procInsId, String bizId) {
        OfficeGoodDetailFragment fragment = new OfficeGoodDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void officeGoodBizDetail(OfficeGoodDetailBean data) {

        if (null != data) {

            mainTitle.setText(data.getDetail().getApplyName()+"的办公用品审批");
            subheadTitle.setText(data.getDetail().getCreateDate());
            name.setText(data.getDetail().getApplyName());
            thingTitle.setText(data.getDetail().getCreateDate());
            time.setText(data.getDetail().getOfficeName());
            leaders.setText(data.getDetail().getCode());
            dutyPeople.setText(data.getDetail().getRemarks());

            if (null != data.getDetail().getOfficeGoodDetail() && data.getDetail().getOfficeGoodDetail().size() > 0) {

                for (int i = 0; i < data.getDetail().getOfficeGoodDetail().size(); i++) {

                    addViewItem(data.getDetail().getOfficeGoodDetail().get(i));

                }

                return;

            }

            llAddview.setVisibility(View.GONE);

        }

    }



    //添加ViewItem
    private void addViewItem(OfficeGoodDetailBean.DetailBean.OfficeGoodsDetailBean bean) {
        View hotelEvaluateView = View.inflate(getActivity(), R.layout.item_officegood, null);
        TextView goodName = hotelEvaluateView.findViewById(R.id.good_name);
        TextView goodNum = hotelEvaluateView.findViewById(R.id.good_num);
        TextView goodRemark = hotelEvaluateView.findViewById(R.id.good_remark);

        goodName.setText(bean.getName());
        goodNum.setText(bean.getNum());
        goodRemark.setText(bean.getRemarks());


        llAddview.addView(hotelEvaluateView);
    }


}
